package com.dalongxin.work.page;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.Target;
import com.dalongxin.work.Constants;
import com.dalongxin.work.EventCenter;
import com.dalongxin.work.R;
import com.dalongxin.work.data.Company;
import com.dalongxin.work.data.Contact;
import com.dalongxin.work.data.Department;
import com.dalongxin.work.data.Fee;
import com.dalongxin.work.page.adapter.PictureAdapter;
import com.dalongxin.work.utils.AndroidBug5497Workaround;
import com.dalongxin.work.utils.HttpUtil;
import com.dalongxin.work.utils.StatusBarUtil;
import com.dalongxin.work.utils.StringUtils;
import com.dalongxin.work.utils.ToastUtil;
import com.dalongxin.work.view.CustomGridView;
import com.dalongxin.work.view.MyCommonEditDialog;
import com.dalongxin.work.view.MyCommonDialog;
import com.dalongxin.work.view.completeimageview.CompleteImageView;
import com.dalongxin.work.view.completeimageview.ImageDownloader;
import com.zzti.fengyongge.imagepicker.PhotoSelectorActivity;
import com.zzti.fengyongge.imagepicker.model.PhotoModel;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.common.util.LogUtil;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 新建费用报销
 */
@ContentView(R.layout.activity_dj_new_fee)
public class DjFeeNewActivity extends BaseActivity implements View.OnClickListener {

    @ViewInject(R.id.tool_bar)
    private Toolbar toolbar;
    @ViewInject(R.id.title_back)
    private ImageButton titleBack;
    @ViewInject(R.id.title_text)
    private TextView titleText;
    @ViewInject(R.id.submit)
    private TextView submit;

    @ViewInject(R.id.tv_choose_fhr)
    private TextView tvChooseFhr;//选择审核人
    @ViewInject(R.id.tv_choose_pzr)
    private TextView tvChoosePzr;//选择批准人
    @ViewInject(R.id.tv_choose_company)
    private TextView tvChooseCompany;//选择公司
    @ViewInject(R.id.tv_choose_department)
    private TextView tvChooseDepartment;//选择部门


    @ViewInject(R.id.tv_choose_sqrq)
    private TextView tvChooseSqrq;//申请日期
    @ViewInject(R.id.tv_add_fee_detail)
    private TextView tvAddFeeDetail;//添加报销事由
    @ViewInject(R.id.layout_fee_detail_list)
    private LinearLayout layoutFeeDetailList;//采购物品清单列表
    @ViewInject(R.id.tv_add_fee_detail_note)
    private TextView tvAddFeeDetailNote;

    @ViewInject(R.id.send_jx_msg_gv_photos)
    private CustomGridView picGridView;
    @ViewInject(R.id.ib_add_pic)
    private ImageButton addPicButton;

    @ViewInject(R.id.et_remark)
    private EditText etBz;//备注
    @ViewInject(R.id.et_je)
    private EditText etJe;//金额
    @ViewInject(R.id.btn_operate)
    private Button btnOperate;

    public static final int REQ_CHOOSE_COMPANY = 1001;
    public static final int REQ_CHOOSE_CONTACT_SHR = 1002;
    public static final int REQ_CHOOSE_CONTACT_PZR = 1003;
    public static final int REQ_CHOOSE_DEPARTMENT = 1004;
    public static final int REQ_ADD_PIC = 2001;
    public Calendar calendar;

    private Company chooseCompany;
    private Department chooseDepartment;
    private Contact chooseFhr;
    private Contact choosePzr;
    private String sqrq;
    private List<Fee.FeeDetail> feeDetailList = new ArrayList<>();
    private List<String> picList = new ArrayList<>();
    private List<String> picWebList = new ArrayList<>();
    private String bz;//备注
    private String je;//金额

    private PictureAdapter pictureAdapter;
    private CompleteImageView completeImageView;//查看大图
    private MyCommonDialog commonDialog;
    private MyCommonEditDialog commonEditDialog;

    public static final String IS_EDIT = "is_edit";
    private int isEdit = 0;// 0新建 1查看
    private Fee bean;
    private boolean canEdit = false;
    private int editState = 0;//0查看状态 1修改状态

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        //this.setSupportActionBar(toolbar);//这样menu才能显示出来【自定义toolbar的话 这个不要设置】
        //getSupportActionBar().setDisplayShowTitleEnabled(false);//去掉默认title的显示
        StatusBarUtil.setPaddingSmart(this, toolbar);
        StatusBarUtil.darkMode(this, false);
        completeImageView = new CompleteImageView(this, new FileDownLoader());
        pictureAdapter = new PictureAdapter(this, picList);
        picGridView.setAdapter(pictureAdapter);
        addPicButton.setOnClickListener(this);
        pictureAdapter.setOnOperationListener(new PictureAdapter.OnOperationListener() {
            @Override
            public void onPicDelete(int position) {
                if(pictureAdapter.getCount()<1){
                    picGridView.setVisibility(View.GONE);
                    addPicButton.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onAddClicked() {
                getPhoto();
            }
        });

        picGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if(i>picList.size()-1){
                    getPhoto();
                    return;
                }
                if(editState == 0) {
                    completeImageView.setUrls(picList, i);
                    completeImageView.create();
                }else {
                    List<File> files = new ArrayList<>();
                    for(String filePath : picList) {
                        files.add(new File(filePath));
                    }
                    completeImageView.setFiles(files, i);
                    completeImageView.setOnDeleteItemListener(
                            new CompleteImageView.OnDeleteItemListener() {
                                @Override
                                public void onDelete(int position) {

                                }
                            });
                    completeImageView.create();
                }
            }
        });

        isEdit = getIntent().getIntExtra(IS_EDIT, 0);
        if(isEdit == 0) {
            titleText.setText("新建费用报销");
            submit.setText("提交");
            switchToEditState();
        }else {
            Bundle bundle = getIntent().getBundleExtra("bundle");
            bean = (Fee) bundle.getSerializable("BEAN");
            if(bean == null) {
                finish();
                return;
            }
            if(bean.getCreateId() == getDefaultAccount().getId() && bean.getStatus() == 0) {
                canEdit = true;
                titleText.setText("查看费用报销");
                submit.setText("修改");
            }else {
                titleText.setText("查看费用报销");
                submit.setVisibility(View.GONE);
            }
            fillDataToPage(bean);
            btnOperate.setVisibility(showOperateBtn(bean) ? View.VISIBLE : View.GONE);
            btnOperate.setOnClickListener(this);
        }
        titleBack.setOnClickListener(this);
        submit.setOnClickListener(this);

        AndroidBug5497Workaround.assistActivity(this);

        calendar = Calendar.getInstance();
    }

    private boolean showOperateBtn(Fee bean) {
        if(bean.getStatus() == 0 && bean.getApproveId1() == getDefaultAccount().getId()) {
            return true;
        }
        if(bean.getStatus() == 1 && bean.getApproveId2() == getDefaultAccount().getId()) {
            return true;
        }
        return false;
    }

    private void fillDataToPage(Fee bean) {
        chooseDepartment = new Department();
        chooseDepartment.setDepartmentId(bean.getDepartmentId());
        chooseDepartment.setDepartmentName(bean.getDepartmentName());
        chooseCompany = new Company();
        chooseCompany.setId(bean.getCompanyId());
        chooseCompany.setName(bean.getCompanyName());
        chooseFhr = new Contact();
        chooseFhr.setId(bean.getApproveId1());
        chooseFhr.setUserName(bean.getApproveName1());
        choosePzr = new Contact();
        choosePzr.setId(bean.getApproveId2());
        choosePzr.setUserName(bean.getApproveName2());

        sqrq = bean.getFillDate();
        bz = bean.getRemark();
        je = bean.getUpperCaseFee();

        tvChooseDepartment.setText(chooseDepartment.getDepartmentName());
        tvChooseFhr.setText(chooseFhr.getUserName());
        tvChoosePzr.setText(choosePzr.getUserName());
        tvChooseCompany.setText(chooseCompany.getName());
        tvChooseSqrq.setText(sqrq);

        etBz.setText(bz);
        etJe.setText(je);

        feeDetailList = bean.getFeeDetailList();
        if(feeDetailList != null && feeDetailList.size() > 0) {
            tvAddFeeDetailNote.setVisibility(View.GONE);
            for(Fee.FeeDetail feeDetail : feeDetailList) {
                TextView tv = new TextView(DjFeeNewActivity.this);
                tv.setText("[报销事由]：" + feeDetail.getReason() + " [报销金额]:" + feeDetail.getFee());
                layoutFeeDetailList.addView(tv);
            }
        }
        picList.clear();
        picList.addAll(bean.getImageUrl());
        if(picList.size() > 0){
            picGridView.setVisibility(View.VISIBLE);
            addPicButton.setVisibility(View.GONE);
        }
        pictureAdapter.setEdit(false);
        pictureAdapter.notifyDataSetChanged();

        switchToViewState();//默认查看状态
    }

    private void switchToEditState() {
        tvChooseFhr.setOnClickListener(this);
        tvChoosePzr.setOnClickListener(this);
        tvChooseCompany.setOnClickListener(this);
        tvChooseDepartment.setOnClickListener(this);
        tvChooseSqrq.setOnClickListener(this);
        if(isEdit == 0) {
            tvAddFeeDetail.setOnClickListener(this);
            tvAddFeeDetail.setVisibility(View.VISIBLE);
        }else {
            tvAddFeeDetail.setOnClickListener(null);
            tvAddFeeDetail.setVisibility(View.GONE);
        }
        etBz.setEnabled(true);
        etJe.setEnabled(true);
    }

    private void switchToViewState() {
        tvChooseFhr.setOnClickListener(null);
        tvChoosePzr.setOnClickListener(null);
        tvChooseCompany.setOnClickListener(null);
        tvChooseDepartment.setOnClickListener(null);
        tvChooseSqrq.setOnClickListener(null);
        tvAddFeeDetail.setOnClickListener(null);
        tvAddFeeDetail.setVisibility(View.GONE);
        etBz.setEnabled(false);
        etJe.setEnabled(false);
    }

    private void uploadFile(final int index) {
        showLoading("正在上传第" + index + "张图片");
        File file = new File(picList.get(index - 1));
        Map<String, String> params = new HashMap<>();
        HttpUtil.getInstance().uploadFile(true, Constants.url_approve_uploadFile, file, params, new Callback.ProgressCallback<JSONObject>() {
            @Override
            public void onSuccess(final JSONObject response) {
                if(response.optInt("ret") == 0) {
                    String webPath = response.optJSONObject("data").optString("filePath");
                    picWebList.add(webPath);
                }
            }

            @Override
            public void onWaiting() {

            }

            @Override
            public void onStarted() {

            }

            @Override
            public void onLoading(long total, long current, boolean isDownloading) {

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {
                int i = index;
                if(i < picList.size()) {
                    i = i + 1;
                    uploadFile(i);
                }else {
                    hideLoading();
                    submitFee();
                }
            }
        });
    }

    private void submitFee() {
        showLoading("提交中");
        Map<String, String> params = new HashMap<>();
        params.put("approveId1", String.valueOf(chooseFhr.getId()));
        params.put("approveId2",String.valueOf(choosePzr.getId()));
        params.put("companyId", String.valueOf(chooseCompany.getId()));
        params.put("departmentId", String.valueOf(chooseDepartment.getDepartmentId()));
        params.put("fillDate", sqrq);

        params.put("imageUrl", StringUtils.listToString(picWebList, ","));
        params.put("jsonData", gson.toJson(feeDetailList));
        params.put("upperCaseFee", je);
        params.put("remark", bz);
        if(canEdit) {
            params.put("id", String.valueOf(bean.getId()));
        }else {
            params.put("id", String.valueOf(0));
        }
        HttpUtil.getInstance().post(true, Constants.url_saveFee, params, new Callback.CommonCallback<JSONObject>() {
            @Override
            public void onSuccess(JSONObject response) {
                LogUtil.e("response=" + response);
                if (response.optInt("ret") == 0) {
                    ToastUtil.showShort("提交成功");
                    EventBus.getDefault().post(EventCenter.call(EventCenter.FEE_REFRESH));
                } else {
                    ToastUtil.showShort(response.optString("msg"));
                }
                finish();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                ToastUtil.showShort("服务器返回失败");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                hideLoading();
            }
        });
    }

    private void getPhoto() {
        if (picList.size() >= PictureAdapter.MAX_NUM) {
            ToastUtil.showShort("已经超过" + PictureAdapter.MAX_NUM +"张图片了");
            return;
        }
        int max_num = PictureAdapter.MAX_NUM - picList.size();
        Intent intent = new Intent(this, PhotoSelectorActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        intent.putExtra("limit", max_num );//number是选择图片的数量
        startActivityForResult(intent, REQ_ADD_PIC);

    }

    private List<PhotoModel> getPicList(List<String> pics) {
        List<PhotoModel> photoList = new ArrayList<>();
        if(pics != null && pics.size() > 0) {
            for(String path : pics) {
                PhotoModel photo = new PhotoModel(path);
                photoList.add(photo);
            }
        }
        return photoList;
    }

    private void submitApprove(String content, int result) {
        showLoading();
        Map<String, String> params = new HashMap<>();
        params.put("msg", content);
        params.put("result", String.valueOf(result));
        params.put("id", String.valueOf(bean.getId()));
        HttpUtil.getInstance().post(true, Constants.url_approveFee, params, new Callback.CommonCallback<JSONObject>() {
            @Override
            public void onSuccess(JSONObject response) {
                commonEditDialog.dismiss();
                LogUtil.e("response=" + response);
                if (response.optInt("ret") == 0) {
                    ToastUtil.showShort("提交成功");
                    EventBus.getDefault().post(EventCenter.call(EventCenter.FEE_REFRESH));
                } else {
                    ToastUtil.showShort(response.optString("msg"));
                }
                finish();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                ToastUtil.showShort("服务器返回失败");
            }

            @Override
            public void onCancelled(CancelledException cex) {
            }

            @Override
            public void onFinished() {
                hideLoading();
            }
        });
    }

    private void preSubmit() {
        if(chooseFhr == null) {
            ToastUtil.showShort("请选择复核人");
            return;
        }
        if(choosePzr == null) {
            ToastUtil.showShort("请选择批准人");
            return;
        }
        if(chooseCompany == null) {
            ToastUtil.showShort("请选择公司");
            return;
        }
        if(chooseDepartment == null) {
            ToastUtil.showShort("请选择部门");
            return;
        }
        if(TextUtils.isEmpty(sqrq)) {
            ToastUtil.showShort("请选择申请日期");
            return;
        }
        if(feeDetailList == null || feeDetailList.size() == 0) {
            ToastUtil.showShort("请添加报销事由");
            return;
        }
        if(picList == null || picList.size() == 0) {
            ToastUtil.showShort("请添加附件");
            return;
        }
        bz = etBz.getText().toString();
        if(TextUtils.isEmpty(bz)) {
            ToastUtil.showShort("请填写备注");
            return;
        }
        je = etJe.getText().toString();
        if(TextUtils.isEmpty(je)) {
            ToastUtil.showShort("请填写金额");
            return;
        }
        commonDialog = new MyCommonDialog(this, "提示消息", "确定提交吗？", "检查一下","提交");
        commonDialog.setOkListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (commonDialog != null && commonDialog.isShowing())
                    commonDialog.dismiss();
                uploadFile(1);
            }
        });
        commonDialog.setCancelListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (commonDialog != null && commonDialog.isShowing())
                    commonDialog.dismiss();
            }
        });
        commonDialog.show();
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.title_back:
                finish();
                break;
            case R.id.submit:
                if(isEdit == 0) {
                    preSubmit();
                }else {
                    if(canEdit) {
                        if (editState == 0) {
                            editState = 1;
                            titleText.setText("修改费用报销");
                            submit.setText("提交");
                            switchToEditState();
                        } else {
                            editState = 0;
                            titleText.setText("修改费用报销");
                            preSubmit();
                        }
                    }
                }
                break;
            case R.id.tv_choose_sqrq:
                int year2 = calendar.get(Calendar.YEAR);
                int month2 = (calendar.get(Calendar.MONTH))+1;
                int day_of_month2 = calendar.get(Calendar.DAY_OF_MONTH);
                new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
                        sqrq = String.format("%d-%d-%d",i,i1+1,i2);
                        tvChooseSqrq.setText(sqrq);
                        tvChooseSqrq.setTextColor(getResources().getColor(R.color.black));
                    }
                },year2, month2, day_of_month2).show();
                break;
            case R.id.tv_add_fee_detail:
                final MyCommonEditDialog.Builder builder = new MyCommonEditDialog.Builder(this);
                commonEditDialog = builder.view(R.layout.dialog_new_fee_detail).widthdp(300).heightdp(320).style(R.style.MyDialogStyle)
                        .addViewOnclick(R.id.cancel, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                commonEditDialog.dismiss();
                            }
                        }).addViewOnclick(R.id.ok, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                EditText etBxsy = (EditText)builder.findViewById(R.id.et_bxsy);
                                EditText etBxje = (EditText)builder.findViewById(R.id.et_bxje);
                                String bxsy = etBxsy.getText().toString();
                                String bxje = etBxje.getText().toString();
                                if(TextUtils.isEmpty(bxsy)) {
                                    ToastUtil.showShort("请填写报销事由");
                                    return;
                                }
                                if(TextUtils.isEmpty(bxje)) {
                                    ToastUtil.showShort("请填写报销金额");
                                    return;
                                }
                                Fee.FeeDetail feeDetail = new Fee.FeeDetail();
                                feeDetail.setReason(bxsy);
                                feeDetail.setFee(Double.valueOf(bxje));
                                feeDetailList.add(feeDetail);
                                TextView tv = new TextView(DjFeeNewActivity.this);
                                tv.setText("[报销事由]：" + bxsy + " [报销金额]:" + bxje);
                                tvAddFeeDetailNote.setVisibility(View.GONE);
                                layoutFeeDetailList.addView(tv);
                                ToastUtil.showShort("添加成功");
                                commonEditDialog.dismiss();
                            }
                        }).build();
                commonEditDialog.show();
                break;
            case R.id.ib_add_pic:
                getPhoto();
                break;
            case R.id.tv_choose_company:
                intent = new Intent(this, CompanyListActivity.class);
                startActivityForResult(intent, REQ_CHOOSE_COMPANY);
                break;
            case R.id.tv_choose_fhr:
                intent = new Intent(this, ContactListActivity.class);
                startActivityForResult(intent, REQ_CHOOSE_CONTACT_SHR);
                break;
            case R.id.tv_choose_pzr:
                intent = new Intent(this, ContactListActivity.class);
                startActivityForResult(intent, REQ_CHOOSE_CONTACT_PZR);
                break;
            case R.id.tv_choose_department:
                intent = new Intent(this, DepartmentListActivity.class);
                startActivityForResult(intent, REQ_CHOOSE_DEPARTMENT);
                break;
            case R.id.btn_operate:
                final MyCommonEditDialog.Builder builder2 = new MyCommonEditDialog.Builder(this);
                commonEditDialog = builder2.view(R.layout.dialog_approve).widthdp(300).heightdp(320).style(R.style.MyDialogStyle)
                        .addViewOnclick(R.id.cancel, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                commonEditDialog.dismiss();
                            }
                        }).addViewOnclick(R.id.ok, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                EditText etSpyj = (EditText)builder2.findViewById(R.id.et_spyj);
                                String spyj = etSpyj.getText().toString();
                                if(TextUtils.isEmpty(spyj)) {
                                    spyj = "";
                                }
                                RadioButton yes = (RadioButton)builder2.findViewById(R.id.radio_result_yes);
                                submitApprove(spyj, yes.isChecked() ? 0 : 1);
                            }
                        }).build();
                commonEditDialog.show();
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(data == null)return;
        if(resultCode == RESULT_OK) {
            switch (requestCode) {
                case REQ_CHOOSE_COMPANY:
                    chooseCompany = (Company)data.getSerializableExtra(CompanyListActivity.DATA_CHOOSE_COMPANY);
                    tvChooseCompany.setText(chooseCompany.getName());
                    tvChooseCompany.setTextColor(getResources().getColor(R.color.black));
                    break;
                case REQ_CHOOSE_CONTACT_SHR:
                    //Department department = (Department)data.getSerializableExtra(DepartmentListActivity.DATA_CHOOSE_DEPARTMENT);
                    chooseFhr = (Contact)data.getSerializableExtra(ContactListActivity.DATA_CHOOSE_CONTACT);
                    tvChooseFhr.setText(chooseFhr.getUserName());
                    tvChooseFhr.setTextColor(getResources().getColor(R.color.black));
                    break;
                case REQ_CHOOSE_CONTACT_PZR:
                    choosePzr = (Contact)data.getSerializableExtra(ContactListActivity.DATA_CHOOSE_CONTACT);
                    tvChoosePzr.setText(choosePzr.getUserName());
                    tvChoosePzr.setTextColor(getResources().getColor(R.color.black));
                    break;
                case REQ_CHOOSE_DEPARTMENT:
                    chooseDepartment = (Department) data.getSerializableExtra(DepartmentListActivity.DATA_CHOOSE_DEPARTMENT);
                    tvChooseDepartment.setText(chooseDepartment.getDepartmentName());
                    tvChooseDepartment.setTextColor(getResources().getColor(R.color.black));
                    break;
                case REQ_ADD_PIC:
                    if (data != null) {
                        ArrayList<String> rawPics = (ArrayList<String>)data.getExtras().getSerializable("photos");//path是选择拍照或者图片的地址数组
                        if(rawPics != null) {
                            picList.addAll(rawPics);
                        }
                        if (picList.size() < 1) {
                            picGridView.setVisibility(View.GONE);
                            addPicButton.setVisibility(View.VISIBLE);
                            pictureAdapter.notifyDataSetChanged();
                        } else {
                            picGridView.setVisibility(View.VISIBLE);
                            addPicButton.setVisibility(View.GONE);
                            pictureAdapter.notifyDataSetChanged();
                        }
                    }
                    break;
            }
        }
    }

    public class FileDownLoader implements ImageDownloader {
        @Override
        public File downLoad(String url, Activity activity) {
            File file = null;
            try {
                file = Glide.with(activity).load(url).downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).get();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return file;
        }
    }
}
